import { HttpMethod, ContentType } from "./utils/HttpMethod"

//接口实体类   
class ApiInfo {
    //服务名称
    serviceName: string;
    //请求url
    url: string;
    //请求方式
    method: HttpMethod;
    //是否json
    contentType: ContentType;
    //参数
    param: any;

    constructor(serviceName: string, url: string, method: HttpMethod, contentType: ContentType, param: any) {
        this.serviceName = serviceName;
        this.url = url;
        this.method = method;
        this.contentType = contentType;
        this.param = param;
    }

    static getApiInfo(apiInfo: ApiInfo) {
        return new ApiInfo(
            apiInfo.serviceName,
            apiInfo.url,
            apiInfo.method,
            apiInfo.contentType,
            apiInfo.param
        );
    }

    static getApiInfoAndData(apiInfo: ApiInfo, data: any) {
        return new ApiInfo(
            apiInfo.serviceName,
            apiInfo.url,
            apiInfo.method,
            apiInfo.contentType,
            data
        );
    }

    static defaultApiInfo() {
        return new ApiInfo(
            '',
            '',
            HttpMethod.POST,
            ContentType.JSON,
            {}
        );
    }
}

export default ApiInfo;